//
//  RXNewFeatureController.swift
//  weibo
//
//  Created by uncle-R on 15/12/16.
//  Copyright © 2015年 uncle-R. All rights reserved.
//

/**
*  ***************************TEST**********************************/
import UIKit

class RXNewFeatureController: UIViewController,UIScrollViewDelegate {
    
    
    lazy var pageControl :UIPageControl = {
        let pageControl  = UIPageControl()
        pageControl.currentPage = 0
        pageControl.pageIndicatorTintColor = UIColor.orangeColor()
        pageControl.numberOfPages = 4
       
        return pageControl
    }()
    
    lazy var scrollView  = UIScrollView()
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

       let scrollView = UIScrollView(frame: view.bounds)
        view .addSubview(scrollView)
        //取消弹簧效果.
         scrollView.bounces = false;
        //设置滚动范围.
        scrollView.contentSize =  CGSizeMake(scrollView.frame.size.width*CGFloat(4), 0)
        scrollView.delegate = self
        scrollView.showsHorizontalScrollIndicator = false
        scrollView.pagingEnabled = true
        self.scrollView = scrollView
        
        view.addSubview(pageControl)
//        CGFloat bottomMargin = 60;
//        CGFloat pageControlH = 20;
//        CGFloat pageControlY = self.view.height - pageControlH - bottomMargin;
        let bottomMargin = 60
        let pageControlH = 20
        let pageControlY = (Int(view.frame.size.height) - pageControlH - bottomMargin)
        
        self.pageControl.frame = CGRect(x: 0, y: Int(pageControlY), width:Int (view.frame.size.width), height:Int(pageControlH))
        pageControl.currentPageIndicatorTintColor = UIColor.orangeColor()
        pageControl.pageIndicatorTintColor = UIColor.grayColor()

//
        let imgW = scrollView.frame.size.width
        let imgH = scrollView.frame.size.height
        for var i=1;i<5;i++ {
            
            let imgView = UIImageView()
            let imgName = "new_feature_"+String(i)
            let image = UIImage(named: imgName)
            imgView.frame = CGRect(x: imgW * CGFloat(i-1), y: 0, width: imgW, height: imgH)
            imgView.image = image
         scrollView .addSubview(imgView)
            if(i == 4){//添加开始按钮.
                
                let btnTest = UIButton()
                btnTest.frame = CGRect(x: 10, y: 10, width: 50, height: 50)
                btnTest.setTitle("xxxxxxxxxxxxx", forState: UIControlState.Normal)
                btnTest.backgroundColor = UIColor.whiteColor()
                
                btnTest .addTarget(self, action: "btnClick", forControlEvents: UIControlEvents.TouchDragInside)
                imgView.addSubview(btnTest)
                
                
                let startView = RXStartView().startViessssss()
                imgView.userInteractionEnabled = true
                
                startView.userInteractionEnabled = true
                
//                startView.subviews[1].userInteractionEnabled = false
                
                let centerX = imgW * 0.5;
                let centerY = imgH * 0.5 + 200;
                startView.center = CGPointMake(centerX, centerY);
                imgView.addSubview(startView)

            }
        }
    }
//MRRK ---UIScrollView的代理方法

    func scrollViewDidScroll(scrollView: UIScrollView) {
        
      self.pageControl.currentPage = NSInteger(self.scrollView.contentOffset.x / scrollView.frame.width)
        
    }
    
    func btnClick(){
        print("btn被点击了")
    }
    
 
}
